package com.crk.shixiguanli.controller;

import com.crk.shixiguanli.entity.Professional;
import com.crk.shixiguanli.service.ProfessionalService;
import com.crk.shixiguanli.util.LayUiTableJson;
import com.crk.shixiguanli.util.Page;
import com.crk.shixiguanli.util.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @author
 * @description:
 * @date 2020/4/6
 */
@RestController
@RequestMapping("professional")
public class ProfessionalController {
    @Autowired
    ProfessionalService professionalService;

    @RequestMapping("manage")
    public ModelAndView manage(){
        ModelAndView modelAndView = new ModelAndView("/workspace/professional/professionalList.html");
        return modelAndView;
    }

    @GetMapping("detail")
    public ModelAndView detail(){
        ModelAndView modelAndView = new ModelAndView("/workspace/professional/professionalAdd.html");
        return modelAndView;
    }

    @RequestMapping("queryProfessionalPage")
    public LayUiTableJson queryProfessionalPage(String college,String professionalName,@RequestParam(defaultValue = "1") int page
            , @RequestParam(defaultValue = "10") int limit){
        Page pageInfo = new Page();
        pageInfo.setCurrentPage(page);
        pageInfo.setSize(limit);
        ResponseResult ResponseResult = professionalService.queryProfessionalPage(college,professionalName,pageInfo);
        LayUiTableJson layUiTableJson = new LayUiTableJson(0,null,pageInfo.getAllRow(),(List)ResponseResult.getData());
        return layUiTableJson;
    }

    @RequestMapping("getProfessional")
    public ResponseResult getProfessional(@RequestParam("id") Integer id){
        return professionalService.getProfessional(id);
    }

    @RequestMapping("saveProfessional")
    public ResponseResult saveProfessional(Professional professional){
        return professionalService.saveProfessional(professional);
    }

    @RequestMapping("deleteProfessional")
    public ResponseResult deleteProfessional(@RequestParam("id") Integer id){
        return professionalService.deleteProfessional(id);
    }

    @RequestMapping("queryAllProfessional")
    public ResponseResult queryAllProfessional(){
        return professionalService.queryAllProfessional();
    }


    @RequestMapping("queryProfessionalByCollege")
    public ResponseResult queryProfessionalByCollege(@RequestParam("college") String college){
        return professionalService.queryProfessionalByCollege(college);
    }
}
